package com.hontech.bv.ui.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.hontech.bv.R
import com.hontech.bv.model.pick.StatusUpdateEvent
import com.hontech.bv.task.eventBus
import com.hontech.bv.ui.fragment.pick.CtrlDelegate
import com.hontech.bv.ui.fragment.pick.StatusDelegate
import com.hontech.bv.utils.log
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

class PickFragment : Fragment() {

    private lateinit var statusDelegate: StatusDelegate

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view = inflater.inflate(R.layout.fragment_pick, null)
        initUi(view)
        return view
    }

    private fun initUi(view: View) {
        statusDelegate = StatusDelegate(view)
        CtrlDelegate(view)
    }

    @Subscribe(threadMode = ThreadMode.MAIN_ORDERED)
    fun onStatusUpdate(_e: StatusUpdateEvent) {
        statusDelegate.update()
    }

    override fun onStart() {
        super.onStart()
        eventBus.register(this)
    }

    override fun onStop() {
        super.onStop()
        eventBus.unregister(this)
    }
}

